package com.wym.lottery.adapter;

import com.wym.lottery.model.Bill;
import com.wym.lottery.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class DataBaseExpandableListAdapter extends BaseExpandableListAdapter {

	private Context context;
	private Bill[] group;
	private Bill[][] child;
	private int mResourceId;

	public DataBaseExpandableListAdapter(Context context, int ResourceID, Bill[] group, Bill[][] child) {
		super();
		this.mResourceId = ResourceID;
		this.context = context;
		this.group = group;
		this.child = child;
	}

	@Override
	public int getGroupCount() {
		return group.length;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return child[groupPosition].length;

	}

	@Override
	public Object getGroup(int groupPosition) {
		return group[groupPosition];
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return child[groupPosition][childPosition];
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	// 设置组控件
	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		View rootView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(mResourceId, null);
		
		TextView time = (TextView) rootView.findViewById(R.id.tv_time);
		TextView scope = (TextView) rootView.findViewById(R.id.tv_scope);
		TextView sell_money = (TextView) rootView.findViewById(R.id.tv_sell_money);
		TextView pay_money = (TextView) rootView.findViewById(R.id.tv_pay_money);
		
		TextView type = (TextView) rootView.findViewById(R.id.tv_type);
		type.setVisibility(View.INVISIBLE);
		
		Bill groupBill=(Bill) getGroup(groupPosition);
		time.append(groupBill.getDate());
		scope.append(groupBill.getScope());
		sell_money.append(groupBill.getSell_money());
		pay_money.append(groupBill.getPay_money());
		return rootView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		View rootView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(mResourceId, null);
		
		TextView time = (TextView) rootView.findViewById(R.id.tv_time);
		TextView scope = (TextView) rootView.findViewById(R.id.tv_scope);
		TextView type = (TextView) rootView.findViewById(R.id.tv_type);
		TextView sell_money = (TextView) rootView.findViewById(R.id.tv_sell_money);
		TextView pay_money = (TextView) rootView.findViewById(R.id.tv_pay_money);
		
		Bill childBill=(Bill) getChild(groupPosition, childPosition);
		time.append(childBill.getDate());
		scope.append(childBill.getScope());
		type.append(childBill.getType_sm());
		sell_money.append(childBill.getSell_money());
		pay_money.append(childBill.getPay_money());
		return rootView;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return false;
	}

}
